// pages/detail/index.js
import { apiUrls, makeRequest } from '../../utils/api'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cdnUrl: 'http://static.xunyi.mobi/',
    items: [],
    windowWidth: 0,
    lng: "113.324520",
    lat: "23.099994",
    markers: [{
      iconPath: "../../images/dw.png",
      id: 0,
      latitude: 23.099994,
      longitude: 113.324520,
      width: 23,
      height: 30
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowWidth: res.windowWidth - 30
        })
      },
    });
    makeRequest({
      url: apiUrls.getShopDetail(options.id),
      method: 'GET',
      data: {
        include: 'category,manager,area'
      },
      success: function (shop) {
        wx.setNavigationBarTitle({
          title: shop.data.data.name
        })
        let lat = shop.data.data.lat;
        let lng = shop.data.data.lng;
        let marker = {
          iconPath: "../../images/dw.png",
          latitude: lat,
          longitude: lng,
          width: 23,
          height: 30
        }
        that.setData({
          items: shop.data.data,
          markers: [marker],
          lat: lat,
          lng: lng
        })
      },
      fail: function (err) {

      }
    })
  },
  onShow: function () {
    
  },
  skipnav(e) {
    let that = this;
    wx.openLocation({
      latitude: that.data.lat,
      longitude: that.data.lng,
      scale: 28,
      name: that.data.items.name,
      address: that.data.items.address,
      success: function (res) {
        //
      },
      fail: function (err) {
        //
      }
    })
  },
  call(e){
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.tel //仅为示例，并非真实的电话号码
    })
  },
  onShareAppMessage: function (res) {
    let that = this;
    return {
      title: that.data.items.name,
      path: `/pages/detail/index?id=${that.data.items.id}`,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})